package nothing.model;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.appfuse.model.BaseObject;

@Entity @Table(name="food_nutrition")
public class FoodNutrition extends BaseObject {
	
	private Long id;
	private Food food;
	private Step step;
	private Nutrition nutrition;
	private BigDecimal qty;
	private BigDecimal per;
	private Measurement measurement;


    @Id @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
	public BigDecimal getPer() {
		return per;
	}
	@Column(name="per", length=5)
	public void setPer(BigDecimal per) {
		this.per = per;
	}
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="measurement_id",referencedColumnName="id",nullable=false, insertable=true, updatable=true)     
	public Measurement getMeasurement() {
		return measurement;
	}
	public void setMeasurement(Measurement unit) {
		this.measurement = unit;
	}
	public void setQty(BigDecimal qty) {
		this.qty = qty;
	}
	@Column(name="qty", length=5)
	public BigDecimal getQty() {
		return qty;
	}
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="nutrition_id",referencedColumnName="id",nullable=false, insertable=true, updatable=true)     
    public Nutrition getNutrition() {
		return nutrition;
	}
	public void setNutrition(Nutrition nutrition) {
		this.nutrition = nutrition;
	}

    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="food_id",referencedColumnName="id",nullable=false, insertable=true, updatable=true)     
	public Food getFood() {
		return food;
	}
	public void setFood(Food food) {
		this.food = food;
	}
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="step_id",referencedColumnName="id",nullable=true, insertable=true, updatable=true)     
	public Step getStep() {
		return step;
	}
	public void setStep(Step step) {
		this.step = step;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((food == null) ? 0 : food.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((measurement == null) ? 0 : measurement.hashCode());
		result = prime * result
				+ ((nutrition == null) ? 0 : nutrition.hashCode());
		result = prime * result + ((per == null) ? 0 : per.hashCode());
		result = prime * result + ((qty == null) ? 0 : qty.hashCode());
		result = prime * result + ((step == null) ? 0 : step.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (getClass() != obj.getClass())
			return false;
		FoodNutrition other = (FoodNutrition) obj;
		if (food == null) {
			if (other.food != null)
				return false;
		} else if (!food.equals(other.food))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (measurement == null) {
			if (other.measurement != null)
				return false;
		} else if (!measurement.equals(other.measurement))
			return false;
		if (nutrition == null) {
			if (other.nutrition != null)
				return false;
		} else if (!nutrition.equals(other.nutrition))
			return false;
		if (per == null) {
			if (other.per != null)
				return false;
		} else if (!per.equals(other.per))
			return false;
		if (qty == null) {
			if (other.qty != null)
				return false;
		} else if (!qty.equals(other.qty))
			return false;
		if (step == null) {
			if (other.step != null)
				return false;
		} else if (!step.equals(other.step))
			return false;
		return true;
	}
	public String toString() {
        return "foodNutrition{" +
        		"id="+id+", "+
        		"food="+food+", "+
        		"step="+step+", "+
        		"qty="+qty+", "+
        		"per="+per+", "+
        		"unit="+measurement+
                "}";
    }
}
